/*
 * Copyright (C) 2015 Daniel Uppenkamp
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.googlecode.maurersmarbles;

import com.google.common.base.Preconditions;

/**
 *
 * @author Daniel Uppenkamp
 */
public class Point {

    /**
     * The x coordinate of the point.
     */
    protected int x;
    /**
     * The y coordinate of the point.
     */
    protected int y;

    /**
     * Creates a new Point at the origin (0,0).
     */
    public Point() {
        this(0, 0);
    }

    /**
     * Creates a new Point with the same location as the given point.
     *
     * @param point the point to copy
     */
    public Point(Point point) {
        Preconditions.checkNotNull(point, "Null point");
        this.x = point.x;
        this.y = point.y;
    }

    /**
     * Creates a new Point at the given x,y location.
     *
     * @param x the x coordinate of the point
     * @param y the y coordinate of the point
     */
    public Point(int x, int y) {
        this.x = x;
        this.y = y;
    }

    /**
     * Returns the x coordinate of the point.
     *
     * @return the x coordinate of the point
     */
    public int getX() {
        return x;
    }

    /**
     * Returns the y coordinate of the point.
     *
     * @return the y coordinate of the point
     */
    public int getY() {
        return y;
    }

    /**
     * Returns a point that is linearly interpolated between point1 and point2
     * by the given weight.
     *
     * @param point1 the first point
     * @param point2 the second point
     * @param weight the weight between point1 and point2 (0.0 - 1.0)
     * @return a point that is linearly interpolated between point1 and point2
     * by the given weight
     */
    public static Point interpolate(Point point1, Point point2, double weight) {

        Preconditions.checkNotNull(point1, "Null point1");
        Preconditions.checkNotNull(point2, "Null point2");

        int x = (int) (point1.getX() + (point2.getX() - point1.getX()) * weight);
        int y = (int) (point1.getY() + (point2.getY() - point1.getY()) * weight);

        return new Point(x, y);

    }

    @Override
    public int hashCode() {
        int hash = 7;
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Point other = (Point) obj;
        if (this.x != other.x) {
            return false;
        }
        if (this.y != other.y) {
            return false;
        }
        return true;
    }

}
